from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-20 14:02:17.448971
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 20, May, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3494
Nobs: 662.000 HQIC: -49.7237
Log likelihood: 8172.90 FPE: 2.00643e-22
AIC: -49.9605 Det(Omega_mle): 1.75316e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.312635 0.060409 5.175 0.000
L1.Burgenland 0.107256 0.038783 2.766 0.006
L1.Kärnten -0.109429 0.020360 -5.375 0.000
L1.Niederösterreich 0.201689 0.080681 2.500 0.012
L1.Oberösterreich 0.122229 0.079900 1.530 0.126
L1.Salzburg 0.256826 0.041240 6.228 0.000
L1.Steiermark 0.043006 0.054071 0.795 0.426
L1.Tirol 0.101452 0.043579 2.328 0.020
L1.Vorarlberg -0.063423 0.038640 -1.641 0.101
L1.Wien 0.032863 0.070682 0.465 0.642
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044075 0.128740 0.342 0.732
L1.Burgenland -0.030814 0.082652 -0.373 0.709
L1.Kärnten 0.040700 0.043390 0.938 0.348
L1.Niederösterreich -0.180552 0.171943 -1.050 0.294
L1.Oberösterreich 0.447837 0.170278 2.630 0.009
L1.Salzburg 0.284715 0.087890 3.239 0.001
L1.Steiermark 0.107060 0.115233 0.929 0.353
L1.Tirol 0.311324 0.092874 3.352 0.001
L1.Vorarlberg 0.021717 0.082347 0.264 0.792
L1.Wien -0.038197 0.150634 -0.254 0.800
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182889 0.031047 5.891 0.000
L1.Burgenland 0.090735 0.019932 4.552 0.000
L1.Kärnten -0.007555 0.010464 -0.722 0.470
L1.Niederösterreich 0.257639 0.041466 6.213 0.000
L1.Oberösterreich 0.155398 0.041064 3.784 0.000
L1.Salzburg 0.042464 0.021195 2.003 0.045
L1.Steiermark 0.024077 0.027790 0.866 0.386
L1.Tirol 0.084210 0.022397 3.760 0.000
L1.Vorarlberg 0.053282 0.019859 2.683 0.007
L1.Wien 0.117841 0.036327 3.244 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109713 0.031072 3.531 0.000
L1.Burgenland 0.046269 0.019948 2.319 0.020
L1.Kärnten -0.014100 0.010472 -1.346 0.178
L1.Niederösterreich 0.185030 0.041499 4.459 0.000
L1.Oberösterreich 0.326876 0.041097 7.954 0.000
L1.Salzburg 0.101871 0.021212 4.802 0.000
L1.Steiermark 0.109182 0.027812 3.926 0.000
L1.Tirol 0.096554 0.022415 4.308 0.000
L1.Vorarlberg 0.059517 0.019874 2.995 0.003
L1.Wien -0.021873 0.036356 -0.602 0.547
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111528 0.057818 1.929 0.054
L1.Burgenland -0.042968 0.037120 -1.158 0.247
L1.Kärnten -0.046134 0.019487 -2.367 0.018
L1.Niederösterreich 0.142426 0.077221 1.844 0.065
L1.Oberösterreich 0.161720 0.076473 2.115 0.034
L1.Salzburg 0.281405 0.039472 7.129 0.000
L1.Steiermark 0.055897 0.051752 1.080 0.280
L1.Tirol 0.164498 0.041710 3.944 0.000
L1.Vorarlberg 0.095843 0.036982 2.592 0.010
L1.Wien 0.077858 0.067651 1.151 0.250
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060782 0.045612 1.333 0.183
L1.Burgenland 0.031992 0.029283 1.093 0.275
L1.Kärnten 0.051310 0.015373 3.338 0.001
L1.Niederösterreich 0.208227 0.060919 3.418 0.001
L1.Oberösterreich 0.316523 0.060329 5.247 0.000
L1.Salzburg 0.041513 0.031139 1.333 0.182
L1.Steiermark 0.006971 0.040827 0.171 0.864
L1.Tirol 0.132017 0.032905 4.012 0.000
L1.Vorarlberg 0.065322 0.029175 2.239 0.025
L1.Wien 0.086168 0.053369 1.615 0.106
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167925 0.054771 3.066 0.002
L1.Burgenland 0.006615 0.035163 0.188 0.851
L1.Kärnten -0.065109 0.018459 -3.527 0.000
L1.Niederösterreich -0.094200 0.073151 -1.288 0.198
L1.Oberösterreich 0.203714 0.072443 2.812 0.005
L1.Salzburg 0.054027 0.037391 1.445 0.148
L1.Steiermark 0.242173 0.049024 4.940 0.000
L1.Tirol 0.500929 0.039512 12.678 0.000
L1.Vorarlberg 0.058260 0.035033 1.663 0.096
L1.Wien -0.072060 0.064085 -1.124 0.261
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148701 0.060678 2.451 0.014
L1.Burgenland 0.004350 0.038956 0.112 0.911
L1.Kärnten 0.060122 0.020450 2.940 0.003
L1.Niederösterreich 0.180641 0.081041 2.229 0.026
L1.Oberösterreich -0.056670 0.080256 -0.706 0.480
L1.Salzburg 0.206563 0.041424 4.987 0.000
L1.Steiermark 0.134499 0.054312 2.476 0.013
L1.Tirol 0.070166 0.043774 1.603 0.109
L1.Vorarlberg 0.143403 0.038812 3.695 0.000
L1.Wien 0.110019 0.070997 1.550 0.121
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373235 0.035814 10.421 0.000
L1.Burgenland 0.000012 0.022993 0.001 1.000
L1.Kärnten -0.021612 0.012071 -1.790 0.073
L1.Niederösterreich 0.217125 0.047833 4.539 0.000
L1.Oberösterreich 0.227950 0.047370 4.812 0.000
L1.Salzburg 0.038973 0.024450 1.594 0.111
L1.Steiermark -0.015710 0.032057 -0.490 0.624
L1.Tirol 0.093372 0.025837 3.614 0.000
L1.Vorarlberg 0.053988 0.022908 2.357 0.018
L1.Wien 0.034409 0.041905 0.821 0.412
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037337 0.119242 0.174137 0.143852 0.100071 0.086825 0.039641 0.212014
Kärnten 0.037337 1.000000 -0.018872 0.135028 0.052695 0.090230 0.440532 -0.060473 0.094049
Niederösterreich 0.119242 -0.018872 1.000000 0.324010 0.130295 0.283642 0.076961 0.162335 0.300707
Oberösterreich 0.174137 0.135028 0.324010 1.000000 0.220292 0.308666 0.167814 0.150794 0.251875
Salzburg 0.143852 0.052695 0.130295 0.220292 1.000000 0.129173 0.099322 0.114660 0.130601
Steiermark 0.100071 0.090230 0.283642 0.308666 0.129173 1.000000 0.138258 0.118493 0.050967
Tirol 0.086825 0.440532 0.076961 0.167814 0.099322 0.138258 1.000000 0.069577 0.148196
Vorarlberg 0.039641 -0.060473 0.162335 0.150794 0.114660 0.118493 0.069577 1.000000 0.007781
Wien 0.212014 0.094049 0.300707 0.251875 0.130601 0.050967 0.148196 0.007781 1.000000